<?php

class Kzend_Controller_Helper_TransactionToken extends Zend_Controller_Action_Helper_Abstract
{
    public function direct()
    {
        return $this->defaultMethod();
    }

    public function defaultMethod()
    {
        return null;
    }

    public function check($formName = null)
    {
        $request = $this->_actionController->getRequest();

        $skey = "tstoken";
        if ($formName != null) {
            $skey = $skey . "_$formName";
        }

        $receivedToken = $request->getPost($skey);
        if ($receivedToken == null) {
            return false;
        }

        $session = new Zend_Session_Namespace("Kzend_TransactionToken");
        $tokenAtSession = $session->{$skey};

        // Removed from the session token transactions.
        $session->{$skey} = null;

        if (!strcmp($tokenAtSession, $receivedToken) == 0) {
            return false;
        }

        return true;
    }

}
